package hoowin.basic.action;

import hoowin.basic.dao.IAccountDao;
import hoowin.basic.dao.springImp.TestDao;
import hoowin.basic.model.Account;
import hoowin.basic.util.Validator;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class LeaveEmail extends ActionSupport {
	private TestDao testDao;
	private IAccountDao accountDao;
	private String message;
	private String email;
	
	public String execute(){
		if(email==null) setMessage("If you have received Dennis' invitation, please leave us your email address.");
		else if(Validator.isEmailAddress(email, true)){
			Account account = accountDao.getAccountByEmail(email);
			if(account==null){
				if(testDao.addEmail(email)==0)setMessage("error.1004");
				else setMessage(getText("message.1001"));
			}else setMessage(getText("message.1002"));
			setEmail("");
		}else setMessage(getText("error.1003"));
		return SUCCESS;
	}

	public void setTestDao(TestDao testDao) {
		this.testDao = testDao;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getMessage() {
		return message;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getEmail() {
		return email;
	}
	public void setAccountDao(IAccountDao accountDao) {
		this.accountDao = accountDao;
	}
}
